import {createSlice} from '@reduxjs/toolkit'
import type {Slice} from "@reduxjs/toolkit";

type initialStateType = {
    user: Record<string, any>,
    authButtonList: Array<string | unknown>,
    authRoleList: Array<string | unknown>,
}
const initialState: initialStateType = {
    user: {},
    authButtonList: [],
    authRoleList: []
}
export const userSlice: Slice = createSlice({
    name: 'user',
    initialState,
    reducers: {
        setUserInfo: (state, {payload}) => {
            state.user = payload.user
        },
        setAuthPermission: (state, {payload}) => {
            state.authButtonList = payload.permissions
        },
        setAuthRole: (state, {payload}) => {
            state.authRoleList = payload.roles
        },
    }
})
export const {setUserInfo, setAuthPermission, setAuthRole} = userSlice.actions
export default userSlice.reducer
